package it.tukano.beanstore;

import java.math.BigDecimal;

/**
 * This bean is used to store the value of the uid base. The uid base is used to
 * generate unique identifiers for the beans stored with the BeanStore utility.
 * @author pgi
 */
public class UidBean {

    private String uid;

    /**
     * Returns the uid base
     * @return the uid base
     */
    public String getUid() {
        return uid;
    }

    /**
     * Sets the uid base
     * @param uid the new uid base
     */
    public void setUid(String uid) {
        this.uid = uid;
    }

    /**
     * Instance initializer
     */
    public UidBean() {
    }

    /**
     * Returns and increments the base uid value
     * @return the uid value before the increment
     */
    public String getAndIncrement() {
        BigDecimal decimal = new BigDecimal(getUid() == null ? "0" : getUid());
        setUid(decimal.add(BigDecimal.ONE).toString());
        return decimal.toString();
    }
}
